package com.itm.lqm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.itm.lqm.entity.Notice;
import com.itm.lqm.util.BaseDao;

public class NoticeDao {
	//查询公告
	public List<Notice> findNoticeAll(){
		try{
			List<Notice> list=new ArrayList<Notice>();
		Connection conn=BaseDao.getConnection();
		PreparedStatement ps=conn.prepareStatement("select * from notice");
		 ResultSet rs=ps.executeQuery();
		 Notice n=null;
		 while(rs.next()){
			 n=new Notice();
			 n.setNid(rs.getInt(1));
			 n.setContent(rs.getString(2));
		     list.add(n);
			 System.out.println(n);
		 }
		 return list;
		 
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return null;
	}
		
	}
	
	//添加公告
	public boolean addNotice(Notice n){
		try{
			Connection con=BaseDao.getConnection();
			PreparedStatement pstm=con.prepareStatement("insert into notice(nid,content) values(?,?)");
			pstm.setInt(1, n.getNid());
			pstm.setString(2,n.getContent());
			int rs = pstm.executeUpdate();
			if(rs>0){
				return true;
			}else{
				return false;
			}
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
}
